<style>
	table.table{
		border:1px solid #000;
		font-size:12px;
		width:100%;
	}
	table{
		border-collapse:collapse;
		width:100%;
	}
	table.table tr td{
		border:1px solid #000;
		padding:0 2px;
	}
</style>
<table>
	<tr>
		<td style="font-size:20; text-align:center;font-weight:bold;"><?=$school_name;?></td>
	</tr>
	<tr>
		<td style="font-size:12px; text-align:center;font-weight:bold;">LIST OF ENROLLED STUDENT(S)</td>
	</tr>
	<tr>
		<td style="font-size:12px; text-align:center;font-weight:bold;">School Year: <?=$school_year;?></td>
	</tr>
	<tr>
		<td style="font-size:12px; text-align:center;font-weight:bold;"><?=$print_title;?></td>
	</tr>
</table>

<?if($students):?>
	<table class="table">
		<tr>
			<th>ID</th>
			<th>Level & Section</th>
			<th>Student Name</th>
			<th>Gender</th>
			<th>Birthdate</th>
			<th>Nationality</th>
			<th>Age By Jul</th>
			<th>Age By Dec</th>
		</tr>
		<?$status = 0;?>
		<?foreach($students as $v):?>
			<?
				
				$levels[] = $v->level_desc;
				$stat = $v->registrar_approved == 1 ? '' : '*';
				$male[$v->level_desc][] = $v->gender == 'male' ? 1 : 0;
				$female[$v->level_desc][] = $v->gender == 'female' ? 1 : 0;
				$gmale[] = $v->gender == 'male' ? 1 : 0;
				$gfemale[] = $v->gender == 'female' ? 1 : 0;
			?> 
			<?if($status !== 0):?>
				<? 
					$z = $levels[count($levels)-2];

					if($z !== $v->level_desc):?>
					<tr>
						<td colspan="8" style="text-align:center;font-weight:bold;">
							(<?=ucwords(strtolower($z));?>)
							Male: <?=@array_sum(array_values($male[$z]));?> |
							Female: <?=@array_sum(array_values($female[$z]));?> |
							Total: <?=@array_sum(array_values($female[$z])) + @array_sum(array_values($male[$z]));?>
						</td>
					</tr>
				<?endif;?>
			<?endif;?>
			
			<tr>
				<td><?=strtolower($v->idno);?></td>
				<td><?=ucwords(strtolower($v->level_desc.' - '.$v->section_name));?></td>
				<td><?=ucwords(strtolower($v->fullname)).$stat;?></td>
				<td><?=ucwords(strtolower($v->gender));?></td>
				<td><?=$v->dob;?></td>
				<td><?=ucwords(strtolower($v->nationality));?></td>
				<td><?=age($v->bdate,'2014-07-01')?></td>
				<td><?=age($v->bdate,'2014-12-01')?></td>
			</tr>
			<?$status = 1;?>
		<?endforeach;?>
		<tr>
			<td colspan="8" style="text-align:center;font-weight:bold;">
				(<?=ucwords(strtolower($z));?>)
				Male: <?=@array_sum(array_values($male[$z]));?> |
				Female: <?=@array_sum(array_values($female[$z]));?> |
				Total: <?=@array_sum(array_values($female[$z])) + @array_sum(array_values($male[$z]));?>
			</td>
		</tr>
		<tr>
			<td colspan="8" style="text-align:center;font-weight:bold;">
				(Grand Total)
				Male: <?=@array_sum(array_values($gmale));?> |
				Female: <?=@array_sum(array_values($gfemale));?> |
				Total: <?=@array_sum(array_values($gmale)) + @array_sum(array_values($gfemale));?>
			</td>
		</tr>
	</table>
<?endif;?>